package org.reyton.entity;

import java.util.List;

public class PageBean<T> {

    //需要显示在页面的集合
    private List<T> list;

    //总页数
    private int totalPage = 1;

    //每页显示的记录数
    private int pageSize = 4;

    //当前第几页
    private int pageIndex = 1;

    //总记录数
    private Long totalCount = 0L;

    public PageBean(int pageSize, int pageIndex, Long total) {
        setPageSize(pageSize);
        setTotalCount(total);
        setPageIndex(pageIndex);
    }

    public void setPageIndex(int pageIndex) {
        if (pageIndex < 1) {
            pageIndex = 1;
        } else if (pageIndex > getTotalPage()) {
            pageIndex = getTotalPage();
        }
        this.pageIndex = pageIndex;
    }

    public void setTotalCount(Long totalCount) {
        if (totalCount > 0) {
            this.totalCount = totalCount;
            //计算总页数
            totalPage = this.totalCount.intValue() % pageSize == 0 ? (this.totalCount.intValue() / pageSize) :
                    this.totalCount.intValue() / pageSize + 1;
        }
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getPageIndex() {

        return pageIndex;
    }


    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public Long getTotalCount() {
        return totalCount;
    }


}


